package com.bawei.module_my.view.fragment

import android.util.Log
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.module_base.net.util.MMKVUtil
import com.bawei.module_base.ui.base.BaseFragment
import com.bawei.module_base.ui.base.BaseViewModel
import com.bawei.module_my.R
import com.bawei.module_my.databinding.FragmentMyBinding
import com.bumptech.glide.Glide


@Route(path = "/my/my_activity")
class MyFragment : BaseFragment<BaseViewModel, FragmentMyBinding>() {
    override fun initData() {
        //头像
       Glide.with(this)
           .load(MMKVUtil.getHeadPic())
           .circleCrop()
           .into( dataBinding.imagePicMy)
        dataBinding.nameMy.text = MMKVUtil.getNickName()
        if (MMKVUtil.getSex() ==1){
            dataBinding.manMy.visibility= View.VISIBLE
            dataBinding.womanMy.visibility= View.GONE
        }else{
            dataBinding.womanMy.visibility= View.VISIBLE
            dataBinding.manMy.visibility= View.GONE
        }

        dataBinding.imagePicMy.setOnClickListener(View.OnClickListener {
            ARouter.getInstance()
                .build("/my/replace_profile_picture_activity")
                .withString("headPic", MMKVUtil.getHeadPic())
                .navigation()
        })


        //我的礼物
        dataBinding.myLiwu.setOnClickListener(View.OnClickListener {
            ARouter.getInstance().build("/my/giftrecordbyuid_activity").navigation()
        })
//我的钱包
        dataBinding.myQianbao.setOnClickListener(View.OnClickListener {
            ARouter.getInstance().build("/my/my/purse_activity").navigation()
        })

        dataBinding.mySixin.setOnClickListener(View.OnClickListener {
            ARouter.getInstance().build("/my/private_message_activity").navigation()
        })
    }


    override fun onResume() {
        super.onResume()
        Log.i("TAG", "onActivityResult: " + MMKVUtil.getHeadPic())
        if (MMKVUtil.getHeadPic() !="" && MMKVUtil.getHeadPic() !=null){
            //dataBinding.imagePicMy.setImageBitmap(BitmapFactory.decodeFile(UriUtils.uri2File(MMKVUtil.getHeadPic().toUri()).absolutePath))

            Glide.with(this@MyFragment)
                .load(MMKVUtil.getHeadPic())
                .circleCrop()
                .into(dataBinding.imagePicMy)
        }
    }

    override fun getViewModelClass(): Class<BaseViewModel> {
      return BaseViewModel::class.java
    }

    override fun getLayout(): Int {
        return R.layout.fragment_my
    }

}